package com.snl.micro.blog.comments.controller;

import com.snl.micro.blog.comments.service.CommentService;
import com.snl.micro.blog.common.param.CommentSaveParam;
import com.snl.micro.blog.common.protocol.ResponseResult;
import com.snl.micro.blog.common.query.CommentQuery;
import com.snl.micro.blog.common.vo.CommentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/comment/")
public class CommentController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private CommentService commentService;

    @GetMapping("hello")
    public String hello() {
        return  "你好，来自端口[%s]的问候".formatted(port);
    }

    @GetMapping("query")
    public ResponseResult<List<CommentVo>> query(CommentQuery query) {
        log.debug("入参：{}",query);
        List<CommentVo> vos =
                commentService.query(query);
        return ResponseResult.success(vos);
    }

    @PostMapping("save")
    public ResponseResult save(CommentSaveParam param) {
        log.debug("入参:{}",param);
        commentService.save(param);
        return ResponseResult.success(null);
    }

}
